<?php
/**注意此文档为UTF-8的编码.
 * Created on 2010-6-29
 *
 * @author EXT <isrn@qq.com>
 *
 */
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
 switch($_REQUEST['op']){
	case 'show':{
		Tr($_GET['tid'],'tid');
		Tr($_GET['zd'],'zd');
		Ts('show1/px.html');
		break;
		}
 	case 'showall':{
			$tid=explode('@',$_POST['tid']);
			$result = mysql_query("SELECT id,tt FROM `se_".$tid[1]."` where tid = '".$tid[0]."' and ".$_POST['zd']." !=0 order  by ".$_POST['zd']." asc");
			if(!$result){
				die('Cannot view the database: '.mysql_error());
				}else{
				while($row = mysql_fetch_assoc($result)){
					$result_arr[] = $row;
					}
					mysql_free_result($result);
					}
				echo json_encode($result_arr);
	
 	break;}
 	case 'pxcs':{
			$tid=explode('@',$_POST['tid']);
			$result = mysql_query("SELECT id,tt FROM `se_".$tid[1]."` where tid = '".$tid[0]."' and ".$_POST['zd']." !=0 order  by ".$_POST['zd']." asc");
			if(!$result){
				die('Cannot view the database: '.mysql_error());
				}else{
				while($row = mysql_fetch_assoc($result)){
					$result_arr[] = $row;
					}
					mysql_free_result($result);
					}
		$px=1;
		foreach($result_arr as $value){
			$gx[$_POST['zd']]=$px;
			Du('sevenel',$tid[1],$gx,'id',$value['id']);
			$px++;
			}
		ext_request('ok');
 	break;}
	case 'px':{
				$tid=explode('@',$_POST['tid']);
				$id=$_POST['nowid'];
				$nowfield=Dgd(array(
					  'db'=>'d_sevenel',
					  'cd'=>"id = $id ",
					  'tn'=>$tid[1],
					  'limit'=>1
				));
			$gx[$_POST['zd']]=$_POST['wz']+1;
			$oldfld=Dgd(array(
					  'db'=>'d_sevenel',
					  'cd'=>"tid = '".$nowfield['tid']."' and ".$_POST['zd']."='".$gx[$_POST['zd']]."' ",
					  'tn'=>$tid[1],
					  'limit'=>1
				));
			$xx[$_POST['zd']]=$nowfield[$_POST['zd']];
//			Du('sevenel','fld',$gx,'id',$id);
			if($xx[$_POST['zd']]>$_POST['wz']){
					$d_sevenel->Desql("update  `se_".$tid[1]."` set ".$_POST['zd']."=".$_POST['zd']."+1 WHERE 1 and tid = '".$nowfield['tid']."' and ".$_POST['zd'].">='".$gx[$_POST['zd']]."' and ".$_POST['zd']." <='".$xx[$_POST['zd']]."' ");
				Du('sevenel',$tid[1],$gx,'id',$id);
				}else{
					$d_sevenel->Desql("update  `se_".$tid[1]."` set ".$_POST['zd']."=".$_POST['zd']."-1 WHERE 1 and tid = '".$nowfield['tid']."' and ".$_POST['zd'].">='".$xx[$_POST['zd']]."' and ".$_POST['zd']." <='".$gx[$_POST['zd']]."' ");
				Du('sevenel',$tid[1],$gx,'id',$id);
					}
				ext_request('ok');
		break;
		}
	case 'del':{
	$_POST['ids']=json_decode(stripslashes($_POST['ids']));
	$tid=explode('@',$_POST['tid']);
	$gx[$_POST['zd']]=0;
	if(is_array($_POST['ids'])){
		foreach($_POST['ids'] as $id){
			Du('sevenel',$tid[1],$gx,'id',$id);
			}				   
		}else{
			Du('sevenel',$tid[1],$gx,'id',$_POST['ids']);
			}
		echo 'ok';
		break;
	}
 }
?>